package o;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class dyz {
    private static final Map<String, c> ˎ = new ConcurrentHashMap();

    static final class c {
        private cjm ˊ;
        private String ˋ;
        private Intent ˎ;
        private fjb ॱ;

        private c() {
        }
    }

    dyz() {
    }

    public static String ˋ(String str, Intent intent, fjb o_fjb, cjm o_cjm) {
        Set<Entry> entrySet = ˎ.entrySet();
        List<String> arrayList = new ArrayList();
        for (Entry entry : entrySet) {
            if (str.equals(((c) entry.getValue()).ˋ)) {
                arrayList.add(entry.getKey());
            }
        }
        if (arrayList.size() >= 50) {
            Logger.ˋ("SafeTargetIntentManager", "too much target intent, delete all the cache values:" + str);
            for (String remove : arrayList) {
                ˎ.remove(remove);
            }
        }
        c cVar = new c();
        cVar.ˎ = intent;
        cVar.ˋ = str;
        cVar.ॱ = o_fjb;
        cVar.ˊ = o_cjm;
        String str2 = UUID.randomUUID().toString() + "###" + System.currentTimeMillis();
        ˎ.put(str2, cVar);
        return str2;
    }

    public static boolean ॱ(@NonNull Activity activity, String str, String str2) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("SafeTargetIntentManager", "registerKey is empty");
            return false;
        }
        c cVar = (c) ˎ.get(str);
        if (cVar == null) {
            Logger.e("SafeTargetIntentManager", "can not found safe intent");
            return false;
        } else if (TextUtils.isEmpty(str2)) {
            Logger.e("SafeTargetIntentManager", "invalid start, can not get Calling Package");
            return false;
        } else if (str2.equals(cVar.ˋ)) {
            ˎ.remove(str);
            if (cVar.ˎ == null && cVar.ॱ == null && cVar.ˊ == null) {
                Logger.e("SafeTargetIntentManager", "can not find target intent");
                return false;
            }
            if (cVar.ˎ != null) {
                cVar.ˎ.addFlags(33554432);
                activity.startActivity(cVar.ˎ);
            } else if (cVar.ˊ != null) {
                cVar.ˊ.ॱ().addFlags(33554432);
                cjk.ˎ().ˋ(activity, cVar.ˊ);
            } else if (cVar.ॱ != null) {
                Intent intent = new Intent();
                intent.addFlags(33554432);
                fiu.ˊ().ॱ(activity, cVar.ॱ, intent);
            }
            return true;
        } else {
            Logger.e("SafeTargetIntentManager", "illegal caller");
            return false;
        }
    }
}
